import { ref } from 'vue';
import { getFactorInfo } from '@/apis/pcf/myModel/modelDetail';

/**
 * 按钮的元素ref
 */
export const buttonRef = ref();

export const useGDetailPopover = () => {
  const tooltipVisible = ref(false);
  const tooltipRow = ref<any>();
  async function handleClickTooltipDetail(e: Event, row: typeof tooltipRow.value) {
    console.log('handleClickTooltipDetail', e, row);
    buttonRef.value = e.currentTarget;
    tooltipRow.value = {};
    try {
      const res = await getFactorInfo(row.factorNo);
      tooltipRow.value = res;
      // NOTE 处理重复点击会引起窗口消失的问题
      setTimeout(() => {
        tooltipVisible.value = true;
      }, 0);
    } catch (error) {
      console.log('error', error);
    }
  }

  return {
    buttonRef,
    tooltipVisible,
    tooltipRow,
    handleClickTooltipDetail
  };
};
